package com.grm.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.grm.common.annotation.HasPerm;
import com.grm.common.annotation.Log;
import com.grm.common.entity.Result;
import com.grm.sys.model.SysLogOperate;
import com.grm.sys.request.log.operate.SysLogOperateQueryParam;
import com.grm.sys.response.SysLogOperateResponse;
import com.grm.sys.service.SysLogOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * desc:操作日志
 *
 * @author gaorimao
 * @since 2023-12-07-13:55
 */
@RestController
@RequestMapping("/sys/log/operate")
public class SysLogOperateController {

    @Autowired
    private SysLogOperateService sysLogOperateService;

    @PostMapping("/list")
    public Result querySelective(@RequestParam Integer pageNum,@RequestParam Integer pageSize, @RequestBody SysLogOperateQueryParam queryParam) {
        // 开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<SysLogOperateResponse> sysLogOperates = sysLogOperateService.querySelective(queryParam);
        PageInfo<SysLogOperateResponse> pageInfo = new PageInfo<>(sysLogOperates);
        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 删除日志
     */
    @Log("删除日志")
    @HasPerm("sys:log:operate:delete")
    @PostMapping("/delete")
    public Result delete(@RequestBody List<Long> ids) {
        sysLogOperateService.delete(ids);
        return Result.success();
    }
}
